package com.xjtu.conan.controller;


import com.xjtu.conan.entity.TheatreCollectInfo;
import com.xjtu.conan.entity.TheatreCommentsInfo;
import com.xjtu.conan.entity.UserInfo;
import com.xjtu.conan.response.AjaxResponse;
import com.xjtu.conan.service.TheatreCollectInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <p>
 * 用户收藏剧场版 前端控制器
 * </p>
 *
 * @author 一只黑猩猩
 * @since 2021-04-19
 */
@CrossOrigin
@RestController
@RequestMapping("/conan/theatre-collect-info")
@Api(value = "用户-剧场版收藏信息管理模块", description = "这是用户-剧场版对应收藏信息CRUD的模块")
public class TheatreCollectInfoController {
    @Autowired
    private TheatreCollectInfoService collectInfoService;

    @ApiOperation(value = "获取某一用户的全部剧场版收藏信息", notes = "根据用户id获取他的剧场版收藏信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = false, defaultValue = "1", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页数量", required = false, defaultValue = "10", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, paramType = "query", dataType = "Long")
    })
    @RequestMapping(value = "/getAllCollectsByuId", method = RequestMethod.GET)
    public AjaxResponse getAllCollectsByuId(@RequestParam(value = "current") Integer current,
                                       @RequestParam(value = "size") Integer size,
                                       @RequestParam(value = "uid") Long uid) {

        return AjaxResponse.success(collectInfoService.getAllCollectByuId(current, size, uid));
    }

    @ApiOperation(value = "添加用户-剧场版收藏信息", notes = "添加用户-剧场版收藏信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tid", value = "剧场版id", required = true, paramType = "form", dataType = "Long")
    })
    @RequestMapping(value = "addTheatreCollects", method = RequestMethod.POST)
    public AjaxResponse addTheatreCollects(@RequestParam(value = "tid") Long tid,
                                           HttpServletRequest request) throws IOException {
        UserInfo loginUser = (UserInfo) request.getSession().getAttribute("loginUser");
        TheatreCollectInfo theatreCollectInfo = new TheatreCollectInfo()
                .setTheatreId(tid)
//                .setUserId(loginUser.getUid())
                .setUserId(1384414001958338562L);
        return AjaxResponse.success("新增收藏信息成功！" + collectInfoService.addTheatreCollect(theatreCollectInfo));
    }

    @ApiOperation(value = "更新用户-剧场版收藏信息", notes = "录入新的用户-剧场版收藏信息并且修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tid", value = "剧场版id", required = true, paramType = "form", dataType = "Long")
    })
    @RequestMapping(value = "updateTheatreCollects", method = RequestMethod.PUT)
    public AjaxResponse updateTheatreCollects(@RequestParam(value = "tid") Long tid,
                                              HttpServletRequest request) throws IOException {
        UserInfo loginUser = (UserInfo) request.getSession().getAttribute("loginUser");
        TheatreCollectInfo theatreCollectInfo = new TheatreCollectInfo()
                .setTheatreId(tid)
//                .setUserId(loginUser.getUid())
                .setUserId(1384414001958338562L);
        return AjaxResponse.success(collectInfoService.updateTheatreCollect(theatreCollectInfo));
    }

    @ApiOperation(value = "删除用户-剧场版收藏信息", notes = "从数据库中删除某个用户-剧场版收藏信息")
    @ApiImplicitParam(name = "tcid", value = "删除收藏id", required = true, paramType = "query", dataType = "Long")
    @RequestMapping(value = "/deleteTheatreCollects", method = RequestMethod.DELETE)
    public AjaxResponse deleteTheatreCollects(@RequestParam(value = "tcid") Long tcid) {
        return AjaxResponse.success("数据库受影响行数->" + collectInfoService.deleteTheatreCollect(tcid));
    }

    @ApiOperation(value = "用户-剧场版收藏信息总数量", notes = "获取数据库中用户-剧场版收藏信息总数量")
    @RequestMapping(value = "/getTotal", method = RequestMethod.GET)
    public AjaxResponse getTotal() {
        return AjaxResponse.success(collectInfoService.getTotal());
    }

}

